﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClickerClimber.Models;
using ClickerClimber.Managers;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ClickerClimber.Model
{
    public class Animation : IGameObject, IGameObjectDrawable
    {
        List<Texture2D> _texture;
        float _timer;
        float _speed;
        int _maxframes;
        int _curframe;
        Vector2 _spritePosition;
        Vector2 _spriteOffset;
        eState _state;

        public enum eState
        {
            ePlaying = 0,
            eDisable
        }

        public void Initialize()
        {
            _maxframes = 0;
            _curframe = 0;
        }

        public void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            _timer += gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
            if (_timer > _speed)
            {
                _timer -= _speed;
                _curframe = (_curframe + 1) % _maxframes;
            }
        }

        public void LoadTextures(Microsoft.Xna.Framework.Content.ContentManager content)
        {

        }

        public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch batch)
        {
            if (_state == eState.ePlaying)
            {
                Color color = Color.White;
                batch.Draw(_texture[_curframe], GameParameters.SCROLL_OFFSET + _spritePosition - _spriteOffset, color);
            }
        }

        public List<Texture2D> Texture
        {
            get
            {
                return _texture;
            }
            set
            {
                _texture = value;
                _spriteOffset.X = _texture[0].Width * 0.5f;
                _spriteOffset.Y = _texture[0].Height * 0.5f;
            }
        }

        public float Timer
        {
            get
            {
                return _timer;
            }
            set
            {
                _timer = value;
            }
        }

        public float Speed
        {
            get
            {
                return _speed;
            }
            set
            {
                _speed = value;
            }
        }

        public int MaxFrames
        {
            get
            {
                return _maxframes;
            }
            set
            {
                _maxframes = value;
            }
        }

        public Vector2 SpritePosition
        {
            get
            {
                return _spritePosition;
            }
            set
            {
                _spritePosition = value;
            }
        }
        public eState State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
            }
        }
    }
}
